High performance freeze-dried dynamic web page generation

ABSTRACT

Dynamic web page generation is optimized by reducing the processing overhead required to parse the web page HTML code for tokens and insert dynamic content. Using the invention, an HTML file for a dynamic web page need be read and parsed only once throughout the life of the server. A software object parses the HTML, decomposes the page into constituent pieces and saves them to data structures as byte streams, which are cached, along with the software object, rendering multiple disk accesses unnecessary when the page is reconstituted. For subsequent requests, the dynamic page is created from the cached version, which is shareable across users and across requests. The optimization reduces server resource usage for dynamic page generation to near zero. The invention is also applicable to other documents combining static and dynamic content that require composition tools for editing.

A portion of the disclosure of this patent document contains material that is subject to copyright protection. The copyright owner has no objection to the reproduction by anyone of the patent document or the patent disclosure, as it appears in the Patent and Trademark Office file or records, but otherwise reserves all copyright rights whatsoever.

BACKGROUND OF THE INVENTION

1. Field of the Invention

The invention relates to processing of electronic documents. More particularly the invention relates to a method of optimizing generation of web pages having dynamic content.

2. Description of Related Technology

Today's Internet websites must deliver an ever-increasing amount of dynamic web page content. Dynamic web page generation is the process whereby a server computer creates HTML “on the fly” to send to a client computer (a Web browser). Dynamic web pages differ from static web pages in that the content of a dynamic web page can only be determined the moment a page request is received by the server computer. While a static web page might display a biography of Abraham Lincoln, content which can be created once and not changed anymore, such a web page and methodology would not be suitable for a web page which displayed the current price of oranges at five local supermarkets. The latter case requires that the server computer utilize dynamic information and compose that information into a web page to send to a client computer.

A common practice employed to aid in the creation of dynamic web pages is the use of HTML containing “tokens”, or “tokenized HTML”. A tokenized HTML file contains some never-changing static information, for example a page heading with the word “Welcome” in it, but also contains some dynamic or “live” areas; for example, an area after “Welcome” where the user's name is to be dynamically placed. This will allow each user to see a Web page that is customized for them. When Sally visits this web page she'll be greeted with a page title that says “Welcome Sally”, and when Joe visits this web page it will be titled, “Welcome Joe”. One of the major advantages of using tokens as placeholders for dynamic content is that they are extremely unobtrusive, allowing technical personnel such as programmers to make sure that dynamic content is placed in certain areas of the page without the necessity of embedding complicated source code in the HTML, which may be very confusing and distracting to someone such as a graphic designer, who is tasked with maximizing the page's aesthetic appeal.

To serve up dynamic web pages, a web server typically creates a dynamic page by loading up a static HTML page with a “token” or “placeholder” in the area where the user's name went. The tokens are of a known form;, for example, “@UserName@,” so that they may be searched for quickly and uniquely. The server searches the page looking for the tokens that refer to dynamic content, e.g. “@UserName@.” Once the token has been located, the server replaces its text with the dynamically discovered text, e.g “Sally.” Replacing a token involves storing all of the text leading up to the token and concatenating it with the dynamic content and all of the text following the token. It must do this for each request it receives (each dynamic page that each user asks for).

Various methods of creating documents with varying content have been proposed. For example, J. Cooper, M. San Soucie, Method of generating document using tables storing pointers and indexes, U.S. Pat. No. 4,996, 662 (Feb. 26, 1991) describe a document processing system having a system architecture that includes a control structure providing supervisory routines for controlling supervisory functions of the system and document manipulation routines for operating upon the documents.

R. Smith, D. Ting, J. Boer, M. Mendelssohn, Document management and production system, U.S. Pat. No. 5,181,162 (Jan. 19, 1993) disclose an object-oriented document management and production system in which documents are represented as collections of logical components that may be combined and physically mapped onto a page-by-page layout.

D. Dodge, S. Follett, A. Grecco, J. Tillman, Method and apparatus for document production using common document database, U.S. Pat. No. 5,655,130 (Aug. 5, 1997) describe a system and method for producing a variety of documents from a common document database. In the described system, source documents are decomposed into encapsulated data elements, in which a data element includes the actual content along with classifying data about the content. The encapsulated data elements are saved to a database, and can be later reassembled to form variation specific documents.

All of the systems described above involve the decomposition of source documents into smaller components, storing the document components in a database and reassembling the document components to form different variations of the source document, or completely new documents. While these systems facilitate the building of variation specific documents such as software documentation, and other engineering documents, they only involve combining and recombining static elements in various ways. The disclosed systems don't provide any way of generating a document “on the fly” that incorporates dynamically discovered information. Furthermore, none of the systems described concern themselves with optimizing the process of incorporating dynamic information into an online document by reducing the required computer resource usage.

Various other methods have been proposed for creating dynamic content in pages for delivery to a client over the Internet on the World-Wide Web (WWW). For example, JAVA SERVER PAGES from Sun Microsystems, Inc. of Menlo Park Calif. or ACTIVE SERVER PAGES from Microsoft Corporation of Redmond Wash. create all of the page content by having the page's Java or C++ server code write all of the page content to the client browser (the output stream). The major drawback of these solutions is that the server code and the page design (the HTML) are both contained in the same HTML file making it extremely difficult for non-programmers (e.g. graphic artists) to use popular page design tools to modify the content on these pages

The primary task of Internet Web server computers is to deliver content (Web pages) to client computers (Web browsers). These server computers are expected to perform these operations extremely rapidly because they are being besieged by, potentially, thousands and thousands of client requests per second. For this reason web developers attempt to reduce bottlenecks in the server software so that the server is performing up to its maximum capacity. The problem, then, arrives when many tokens in many dynamic pages need to be repeatedly replaced with dynamic content. Though the example in the preceding paragraph only contained a single token, the reality is that dynamic Web pages are normally far more complex than in this example, and might have 20 or more tokens.

Without any optimization, on each request, the server would have to re-read the base HTML file from disk, search and replace all occurrences of each token, and then write the newly created content stream to the client's return stream. The problem with this approach is that it is extremely time consuming. Even if the file is read from disk only once (i.e. it's cached) the act of replacing all occurrences of all tokens in the file is a very slow and very costly operation. It is so slow that it would likely be the primary bottleneck in the server software. Additionally, buying more hardware, bandwidth, etc. will not solve this problem because no matter how many machines were running concurrently, on each client request each web server would have to re-read and re-replace the page's content.

There exists, therefore, a need in the art for a way to reduce the processing overhead required to parse the HTML code of a web page that requires the incorporation of dynamic content in order to locate areas, identified by tokens, wherein the dynamic contented is to be inserted, and replacing the tokens with the dynamic content.

SUMMARY OF THE INVENTION

The invention provides a process in which an HTML file for a web page incorporating dynamic content is read and parsed once and only once throughout the life of the server. The dynamic HTML file is read from the server's local disk. A ContentComposer, a software object, parses the HTML and decomposes the page into its constituent pieces, which are stored in multiple data structures. The data structures and the ContentComposer are cached, allowing extremely rapid access. For subsequent page requests, the dynamic page is created from the in-memory version. This in-memory version can be shared across users and across requests. Reading and decomposing the HTML file and performing token replacement is so highly optimized that server resource usage, (memory, CPU, etc.) is near zero.

While the preferred embodiment provides a particular implementation directed to replacement of tokens in HTML files by a web server, it is generally applicable to any situation in which documents need to be

-   -   be editable using reasonable and current tools; and     -   be dynamic in that some of its content is static but other         pieces of its content are created dynamically and will likely         change from one creation to the next.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 provides a top-level block diagram of a process for optimizing generation of a computer readable document incorporating static and dynamic content, according to the invention;

FIG. 2 provides a block diagram of a sub-process for “freeze-drying” raw content from a document template, according to the invention;

FIG. 3 provides a block diagram of a plurality of data structures for storing the freeze-dried content of FIG. 2, according to the invention; and

FIG. 4 provides a block diagram of a sub-process for composing a document from the freeze-dried content of FIG. 3, according to the invention.

DETAILED DESCRIPTION

Overview

A description of the details and function of the present invention is provided below. The source code listed in APPENDIX A, written in JAVA, details the implementation of a preferred embodiment of the invention. The patentee has no objection to the reproduction of the source code or other information for the purpose of obtaining and maintaining a valid patent. However, the patentee otherwise reserves all copyright interests.

The invention is embodied as both a process to be executed on a computer, typically a web server, and a computer program product providing computer readable program code means for executing the various steps of the process. The computer readable program code is embodied on a computer readable medium. The computer readable medium may be either fixed, such as a mass storage device or a memory, or it may be removable, such as a CD or a diskette. The invention is implemented through the use of conventional computer programming techniques well known to those skilled in the art. While the source code provided in the attached appendix is written in JAVA, other programming languages would also be suitable for programming the invention. While the invention is preferably programmed in an object-oriented language such as JAVA or C++, other embodiments, consistent with the spirit and scope of the invention, programmed in procedural languages or scripted languages, are also possible.

Referring now to FIG. 1, the invention provides a process for optimizing generation of a computer readable document incorporating static and dynamic content 10, particularly web pages being served up to a client in response to a request from a user. As previously mentioned, one of the most common ways of generating web pages having dynamic content is to start with a page template. Typically, the page template is a file of HTML code containing placeholders where the dynamic content is to be inserted. The placeholders usually consist of tokens. For example “@Username@” might be typically used as a placeholder for a user's name. When the template is created, or after it is edited, it is saved to disk, typically on a web server. Thereafter, the HTML file is read from the disk and parsed to locate the “live” or dynamic sections, which have been set off or reserved by the tokens. The invention provides a process in which the HTML file need be read from disk and parsed only once, unlike prior art methods, which require that the file be read and parsed every time a client requests the page.

File Reads

In the current embodiment of the invention, the HTML file is read from the disk 11 by means of a helper software object tasked with various utility file operations, such as reading in files, getting file lists and so on. Reading pages of “static” content is performed by a “getContent( )” method embodied in the helper object. The getContent(0 method of the helper object retrieves the raw HTML file and stores the raw content to the cache as a string. More detailed descriptions of the operation of the helper object and the “getContent( )” method are to be found by referring to the documentation provided in the enclosed Appendix.

Content Composer

When parsing the HTML file for caching and token replacement purposes, the goal is to separate the HTML file into its component static pieces, dynamic pieces, and replaceable token pieces. A common term of art for this process is “freeze-drying” 12. The invention provides a ContentComposer class that is the sole parser and manager of this freeze-dried content. Each HTML file has a separate instance of the ContentComposer object associated with it. In keeping with conventional methods of object-oriented programming, in which an object includes both instructions and the associated data, the ContentComposer object for a particular page includes the implementation logic and the raw content string. When a file is loaded, the helper object checks to see if a ContentComposer object exists for the file. If the file has no associated ContentComposer object, the helper object creates one 20. A global HashMap, held in the cache, provides storage for ContentComposer objects. Thus, following creation of the ContentComposer, the new ContentCompser object is stored to the global Hashmap. In this way, the deconstructed file data is effectively cached, so that it may be used on subsequent invocations 21.

After being cached, ContentComposer parses the HTML file by “decomposing” the raw code string, separating it into its various components 22. Components are one of three types:

-   -   blocks of immutable content containing no tokens;     -   lines of immutable content that surround tokens; and     -   token replacement values.

According to a preferred embodiment of the invention, a token comprises a string that starts and ends with the “@” characters and contains no embedded white space, newline characters, colons, semi-colons, or commas. However, the delimiting characters are a mere matter of choice, dictated in this case by the conventional manner of creating tokenized HTML code.

In some cases, only the token is replaced, in other cases, the entire line containing the token is replaced. For example, the method allows calling processes to replace the whole line of text that the token was on, which is a frequent operation for callers replacing <li> or <select> items.

As previously described, the helper object provides a raw code string to the ContentComposer for parsing. A setContents( ) method within the ContentComposer provides most of the parsing logic for the invention. The setContents( ) method parses the raw content string to locate delimiting characters. Upon locating a delimiting character, the parsing engine evaluates the string for the presence of the previously indicated illegal characters—white space, newline characters, colons, semi-colons, or commas. The presence of any illegal characters indicates that the delimiting, character is not associated with a valid token. “@foo bar@” or “keith@iamaze.com” are examples of such invalid strings. As the various page components are identified, they are stored to one of several data objects that are also associated with the ContentComposer. After the page components are identified, the page is decomposed by saving the separate components to a plurality of data structures 23. These data structures are described in greater detail below. It should be noted that the process of separating the page into components and storing them in the data structures constitutes the process commonly known as “freeze-drying.” While, for the purpose of description, the data and the data structures are described separately from the logic and instructions, they are, in fact, all associated within a single ContentComposer object, which is held in the cache. Thus, as with the raw code string, the data structures containing the page components are effectively cached, eliminating the necessity of any further disk accesses when the HTML file is composed.

After the page components are cached, calling processes can ask the ContentComposer to perform token replacment, which it can do very fast: in 0-1 time, the tokens are stored in a HashMap as described below. The final part of SXContentComposer's lifecycle is when the caller asks the ContentComposer to “compose( )” itself, thus creating a page for download to a client 13. The compose( ) method itself provides additional important performance gains. Rather than recomposing the HTML into a string, and passing the string to the calling process, extremely wasteful of memory and processor time, the ContentComposer walks through the data structures and writes the data to an output stream as it is walking 14.

This implementation holds three primary data structures. It is necessary to hold this parsed data in three disparate, but linked, data structures because the data must be accessed from a number of different “angles”, and for a number of different purposes. The composer will need access to all the original static text, plus some way to gather the token replacement values. The caller will need to replace token values (by specifying the token name), or the whole line the token is appears on. The caller may also want to inspect the line a token appears on.

Data Structures

The three primary data structures are as follows:

The first is an array of immutable content broken up into “chunks” 30. Each chunk is either a text block with no “@foo@” tokens, or it is an integer object pointing to the index of a token replacement object, (SXTokenLine) which will supply the values (string) for that chunk.

The second data structure is also an array of immutable content: an array of the token-replacement-objects mentioned above 31, and pointed to by the chunks array. These token-replacement-objects are of type Token Line and they hold the static text that immediately precedes and follows a token. They also hold the raw token name itself (e.g. “@FooBar@”) as well as a pointer to an object stored within the third data structure, a structure that holds the replacement line or replacement value associated with this token. This final object is of type Token. While the names assigned to the various page component types in the current embodiment are descriptive of their content, they are primarily a matter of choice.

The third data structure is a HashMap with all the tokens from the raw content as keys and all the replacement values set by the calling process as the values 32. These replacement values are of type Token Object, which can hold a replacement line or a replacement value for a token.

Note that the immutable text chunks never change throughout the life of this object, while the values stored in the tokens and replacement values HashMap are likely to change every time content is created, since tokens and replacement values represent the dynamic portion of the content.

Furthermore, to reduce the overhead of future writes to streams, and to reduce the excessive creation of string objects, the static data in both the immutable text chunks array as well as the immutable token lines array is stored as byte( ), rather than string.

Compose( ) Method

The Compose( ) method of the ContentComposer writes each text chunk and token replacement value to an output stream in sequential order, creating a single, coherent, token-replaced text stream.

As the ContentComposer walks the immutable text chunks array 40, if it encounters an array entry that is a token rather than a chunk of text, instead of concatenating the actual token, it concatenates the value for the token found in the tokens and replacement values HashMap 41.

The specific process and data structures used by the ContentComposer are described in greater detail in the example provided below.

EXAMPLE Sample Raw Content

-   -   <html>     -   <title>iAmaze Presentation Tool </title>     -   <h1>Welcome to iAmaze, @UserName@!</h1>     -   <br>     -   <br>     -   Would you like to work on the presentation you last worked on,         named @LastPresentation>?     -   <br>     -   If so, click here.     -   </html>

Sample Raw Data Structures Created from Raw Content

Immutable Text Chunks Array

-   -   immutableTextChunksArray[0]=“<html>         -   <title>iAmaze Presentation Tool </title>”     -   immutableTextChunksArray[1]=“new integer(0)” use to look up, at         index=0, this token's pre- & post-SXTokenLine line text objects         in the “immutableTokenLines” array.)     -   immutableTextChunksArray[2]=“! </h1>     -   <br>     -   <br>”     -   immutableTextChunksArray[4]=“?     -   <br>     -   If, so click-here. </html>”         Immutable Token Lines Array     -   ImmutableTokenLinesArray[0]={SXTokenLine{prefix=“<hi>Welcome to         iAmaze, ” suffix=“!</h1>”, pointer to SXToken object in the         tokensAndReplacementValues}     -   ImmutableTokenLinesArray[1]={SXTokenLine{prefix=“Would you like         to work on the presentation you last worked on, named: “,         suffix=“”, pointer to SXToken object in the         tokensAndReplacementValue}         Tokens and Replacement Values HashMap     -   TokensAndReplacementValues={     -   “@UserName@”, SXToken {replacemetForToken=null,         -   replacementForTokenLine=null}},     -   {“@LastPresentation@”, SXToken{replacementForToken=null,         -   replacementForTokenLine==null}}}             Thus, the data structures for the example page appear as             shown above immediately adter the parsing or “freeze-dry”             process. After being supplied values by calling process, for             example, in response to a request from a user, two separate             methods are called to replace the token with the new             content:             After calls to:     -   anSXContentComposer.replaceLineContainingToken (“@UserName@”,         “<h1> Welcome to work, Keith!</h1>”);     -   anSXContentComposer.replaceToken (“@LastPresentation@”, “1999         Harleys”);         The tokens and replacement values HashMap look as below:     -   tokensAndReplacementValues=     -   {{“@UserName@”, SXToken {replacementFortoken=null,         -   replacementForTokenLine=“<h1>Welcome to work, Keith!         -   </h1>”}},     -   {“@LastPresentation@”, SXToken {replacementForToken=         -   “1999Harleys”, replacementForTokenLine=null}}}

The first call replaces the entire line containing the token. The second call replaces only the token. The immutable text chunks and the immutable token lines arrays remain the same, since they contain immutable data.

A call to SXContentComposer's Compose( ) or toString( ) methods generates the following:

-   -   <html>     -   <title>iAmaze Presentation Tool</title><h1>Welcome to work,         Keith!</title>     -   <br>     -   <br>     -   Would you like to work on the presentation you last worked on,         named 1999 Harleys?<br>     -   If so, click here.     -   </html>

The toString( ) method outputs a string to the output stream in a fashion similar to the Compose( ) method. More detailed description of the toString( ) method as well as the replaceLineContainingToken( ), and replaceToken( ) methods is to be found below.

Although the invention has been described herein with reference to certain preferred embodiments, one skilled in the art will readily appreciate that other applications may be substituted without departing from the spirit and scope of the present invention. Accordingly, the invention should only be limited by the claims included below. 

1. A process for optimizing generation of a computer readable document incorporating static and dynamic content, comprising the steps of: creating and caching at a server an instance of a first software object, said first software object including: a template for said document, said template including placeholders for dynamically-discovered content; a plurality of data structures; and computer-readable instructions for processing said template by said first software object; decomposing said template into separate page components by said first software object according to said instructions; saving said page components and said dynamically-discovered content to said data structures by said first software object according to said instructions; receiving a request for said document from a client; recomposing said document by said first software object; and outputting said recomposed document to said client; wherein a separate instance of said first software object is created and cached for each document.
 2. A process according to claim 1, wherein the step of creating and caching an instance of said first software object comprises the steps of: retrieving said template by a second software object, said template comprising an HTML file; creating an instance of said first software object for said file, if one does not already exist, said instance including said HTML file as a string; and storing said instance to a global hashmap, said global hashmap held in said cache, wherein said first software object comprises a content composer.
 3. A process as in claim 2, wherein said step of decomposing said template comprises the steps of: parsing said template string by said content composer; and locating placeholders in said template for said dynamic content.
 4. The process of claim 2, wherein said placeholders comprise tokens, and wherein said document components comprise: blocks of immutable content, having no tokens therein; token replacement objects, said token replacement objects comprising blocks of static text preceding and following a token; and raw token names.
 5. The process of claim 4, wherein said document components further comprise replacement values and replacement lines for said tokens, wherein said replacement values and replacement lines comprise said dynamic content.
 6. The process of claim 5, wherein said step of saving said components and said dynamically discovered content comprises the steps of: converting said components into byte streams; and saving said byte streams to said data structures.
 7. The process of claim 6, wherein said data structures comprise: a first array of immutable content containing: said blocks of immutable content and integer objects pointing to indices of one or more objects in a second array; said second array, containing said token replacement objects and said raw token names, wherein blocks of immutable-content having tokens therein are built from said token replacement objects and said raw token names, and wherein raw token names further include pointers to corresponding keys in a third data structure; and a hash map, said hash map comprising said third data structure, wherein keys of said hash map comprise said raw token names and wherein values comprise replacement values and replacement lines for said tokens.
 8. The process of claim 7, wherein said step of recomposing said document comprises: walking said data structures and writing said data to a stream as it walks through the data structures, so that a document is created wherein said tokens are replaced with either of said replacement values or said replacement lines.
 9. The process of claim 2, wherein said cache and said template are located on a server and said request is received from a client in communication with said server.
 10. The process of claim 9, wherein said dynamically discovered content comprises content received from said client.
 11. A computer program product for optimizing generation of a computer readable document incorporating static and dynamic content, said computer program product comprising a computer usable storage medium having computer readable computer code means embodied in the medium, the computer code means comprising computer readable program code means for: creating and caching at a server an instance of a first software object, said first software object including: a template for said document, said template including placeholders for dynamically-discovered content; a plurality of data structures; and computer-readable instructions for processing said template by said first software object; decomposing said template into separate page by said first software object components according to said instructions; saving said page components and said dynamically-discovered content to said data structures by said first software object according to said instructions; receiving a request for said document from a client; recomposing said document by said first software object; and outputting said recomposed document to said client; wherein a separate instance of said first software object is created and cached for each document.
 12. A computer program product according to claim 11, wherein the computer readable code for creating and caching an instance of said first software object comprises computer readable code for: retrieving said template by a second software object, said template comprising an HTML file; creating an instance of said first software object for said file, if one does not already exist, said instance including said HTML file as a string; and storing said instance to a global hashmap, said global hashmap held in said cache, wherein said first software object comprises a content composer.
 13. A computer program product as in claim 12, wherein said computer readable code for decomposing said template comprises the computer readable code for: parsing said template string by said content composer; and locating placeholders in said template for said dynamic content.
 14. A computer program product as in claim 12, wherein said placeholders comprise tokens, and wherein said document components comprise: blocks of immutable content, having no tokens therein; token replacement objects, said token replacement objects comprising blocks of static text preceding and following a token; and raw token names.
 15. A computer program product as in claim 14, wherein said document components further comprise replacement values and replacement lines for said tokens, wherein said replacement values and replacement lines comprise said dynamic content.
 16. A computer program product as in claim 15, wherein said computer readable code for saving said components and said dynamically discovered content comprises the computer readable code for: converting said components into byte streams; and saving said byte streams to said data structures.
 17. A computer program product as in claim 12, wherein said cache and said template are located on a server and said request is received from a client in communication with said server.
 18. A computer program product as in claim 17, wherein said dynamically discovered content comprises content received from said client.
 19. A computer program product as in claim 16, wherein said data structures comprise: a first array of immutable content containing: said blocks of immutable content and integer objects pointing to indices of one or more objects in a second array; said second array, containing said token replacement objects and said raw token names, wherein blocks of immutable content having tokens therein are built from said token replacement objects and said raw token names, and wherein raw token names further include pointers to corresponding keys in a third data structure; and a hash map, said hash map comprising said third data structure, wherein keys of said hash map comprise said raw token names and wherein values comprise replacement values and replacement lines for said tokens.
 20. A computer program product as in claim 19, wherein said computer readable code for recomposing said document comprises computer readable code for: walking said data structures and writing said data to a stream as it walks through the data structures, so that a document is created wherein said tokens are replaced with either of said replacement values or said replacement lines. 